<template>
    <div>
        <van-form :ref="formData">
            <!-- 编辑节点2 -->
            <div v-if="this.subTaskInfo.status !== '3' ">
              <van-row class="rowLabel">
                <van-col span="12"  class="colCss">
                    <div class="taskName">任务编号：</div>
                    <div class="taskInfo">{{subTaskInfo.taskCode}}</div>
                </van-col>
                <van-col span="12"  class="colCss">
                    <div class="taskName">任务名称：</div>
                    <div class="taskInfo">{{mainTaskInfo.taskName}}</div>
                </van-col>
              </van-row>
              <van-row class="rowLabel">
                <van-col span="12" class="colCss">
                  <div class="taskName">电芯型号：</div>
                  <div class="taskInfo">{{subTaskInfo.electricCoreTypeName}}</div> 
                </van-col>
                <van-col span="12" class="colCss">
                  <div class="taskName">电芯编号：</div>
                  <div class="taskInfo">{{subTaskInfo.electricCoreCode}}</div>
                  <van-button type="primary" plain size="mini" style="float:right" @click="showAddElementPopup = true">新增项目</van-button>
                  <van-popup v-model:show="showAddElementPopup" round position="bottom" >
                    <van-picker
                            :columns="dynElementNameList"
                            @cancel="showAddElementPopup = false"
                            @confirm="confirmDynElement"
                          />
                  </van-popup>
                </van-col>
              </van-row>
              <!--固定元素-->
              <van-collapse v-model="fixedActiveIndexs">
                <template v-for="(item, index) in fixedConfigElementList">
                <van-collapse-item :title="item.name" :name="index">
                  <van-row class="rowLabel" v-if="item.type === 1 || item.type === 5">
                    <van-col :span="item.unit ? 7 : 8">
                      <!-- 输入框 -->
                      <van-field
                          v-model="item.configValue"
                          :label="item.name + '：'"
                          placeholder="请输入"
                      />
                    </van-col>
                    <van-col span="1" class="formUnit" v-if="item.unit != null && item.unit != ''">
                      {{ item.unit }}
                    </van-col>
                    </van-row>
                    <van-row class="rowLabel" v-if="item.type === 3 || item.type === 5">
                      <van-col span="16">
                        <van-field name="factoryCode"
                            v-model="item.selectValue"
                            label="是否缺陷：">
                          <template #input>
                            <van-radio-group v-model="item.selectValue" direction="horizontal">
                              <van-radio v-for="(item,index) in item.okColumns" 
                                :key="index"
                                :name="item.value" 
                                shape="square"
                                @click="onConfirmOK(item)">
                                {{item.text}}
                            </van-radio>
                            </van-radio-group>
                          </template>
                        </van-field>
                      </van-col>
                    </van-row>
                    <van-row class="rowLabel" v-if="item.isThrowDesc === 1">
                      <!--有异常描述 -->
                      <van-col span="16">
                        <van-field-checkbox
                          v-model="item.defectTypeIdList"
                          label="缺陷类型："
                          placeholder="请选择缺陷类型"
                          :item="item"
                          :columns="item.currentNodeDefectTypeList"
                          :option="{label:'defectName', value:'defectTypeId'}"
                          :disabled="item.noDefectType"
                          @confirm="selectDefectType"
                        />
                      </van-col>
                    </van-row>
                    <van-row class="rowLabel" v-if="item.isThrowDesc === 1">
                      <van-col span="16" v-if="item.isThrowDesc === 1">
                        <van-field
                              v-model="item.descr"
                              label="异常描述："
                              placeholder="请输入异常描述"
                              :disabled="item.noDefectType"
                              :rules="[{ required: true, message: '请输入异常描述' }]" />
                      </van-col>
                    </van-row>
                    <van-row class="rowLabel" v-if="item.type == 4">
                      <van-col span="24">
                        <van-field span="8" 
                          v-model="item.configValue"
                          rows="2"
                          autosize
                          :label="item.name + '：'"
                          type="textarea"
                          maxlength="100"
                          placeholder="请输入描述"
                          show-word-limit />
                      </van-col>
                    </van-row>
                    <!-- 照片 -->
                    <van-row class="rowLabel" v-if="item.hasImage === 1">
                      <uploader 
                        :fileList="item.taskNodeFileList"
                        :title="'照片：'"
                        :taskCode = "subTaskInfo.taskCode"
                        :processConfigId = "item.processConfigId"
                        :elementIndex = "index"
                        :fixed="1"
                        preview-size="20"
                        @fileChange="fileChange"
                      />
                    </van-row>
                    <van-row class="rowLabel" v-if="item.interfaceImage === 1">
                      <van-col :span="6">
                        <van-button plain type="primary" size="mini" style="margin-left:70px;" @click="startGetSubTaskPoleGroupFilesFromAI(item)">开始获取极组照片</van-button>
                        <van-button plain type="primary" size="mini" style="margin-left:6px;" @click="querySubTaskPoleGroupFiles(item)">刷新照片</van-button>
                      </van-col>
                    </van-row>
                </van-collapse-item>
                </template>
              </van-collapse>
              
              <!-- 动态元素 -->
              <van-collapse v-model="dynActiveIndexs">
                <template v-for="(item, index) in dynConfigedElementList" :key="item.name">
                  <van-collapse-item :title="item.name" :name="index">
                  <van-row class="rowLabel" v-if="item.type === 1 || item.type === 5">
                    <van-col span="1"><van-button type="primary" plain size="mini" @click="deleteDynElement(index)">删除</van-button></van-col>
                    <van-col :span="item.unit ? 6 : 7">
                      <!-- 输入框 -->
                      <van-field
                          v-model="item.configValue"
                          :label="item.name + '：'"
                          placeholder="请输入"
                      />
                    </van-col>
                    <van-col span="1" class="formUnit" v-if="item.unit != null && item.unit != ''">
                      {{ item.unit }}
                    </van-col>
                    </van-row>
                    <van-row class="rowLabel" v-if="item.type === 3 || item.type === 5">
                      <van-col span="1"><van-button type="primary" plain size="mini" @click="deleteDynElement(index)" v-if="item.type != 5">删除</van-button></van-col>
                      <van-col span="15">
                        <van-field name="factoryCode"
                            v-model="item.selectValue"
                            label="是否缺陷：">
                          <template #input>
                            <van-radio-group v-model="item.selectValue" direction="horizontal">
                              <van-radio v-for="(item,index) in item.okColumns" 
                                :key="index"
                                :name="item.value" 
                                shape="square"
                                @click="onConfirmDynOK(item)">
                                {{item.text}}
                            </van-radio>
                            </van-radio-group>
                          </template>
                        </van-field>
                      </van-col>
                    </van-row>
                    <van-row class="rowLabel" v-if="item.isThrowDesc === 1">
                      <!--有异常描述 -->
                      <van-col span="16">
                        <van-field-checkbox
                          v-model="item.defectTypeIdList"
                          label="缺陷类型："
                          placeholder="请选择缺陷类型"
                          :item="item"
                          :columns="item.currentNodeDefectTypeList"
                          :option="{label:'defectName', value:'defectTypeId'}"
                          :disabled="item.noDefectType"
                          @confirm="selectDefectType"
                        />
                      </van-col>
                    </van-row>
                    <van-row class="rowLabel" v-if="item.isThrowDesc === 1">
                      <van-col span="16" v-if="item.isThrowDesc === 1">
                        <van-field
                              v-model="item.descr"
                              label="异常描述："
                              placeholder="请输入异常描述"
                              :disabled="item.noDefectType"
                              :rules="[{ required: true, message: '请输入异常描述' }]" />
                      </van-col>
                    </van-row>
                    <van-row class="rowLabel" v-if="item.type == 4">
                      <van-col span="24">
                        <van-field span="8" 
                          v-model="item.configValue"
                          rows="2"
                          autosize
                          :label="item.name + '：'"
                          type="textarea"
                          maxlength="100"
                          placeholder="请输入描述"
                          show-word-limit />
                      </van-col>
                    </van-row>
                    <!-- 照片 -->
                    <van-row class="rowLabel" v-if="item.hasImage === 1">
                      <uploader 
                        :fileList="item.taskNodeFileList"
                        :title="'照片：'"
                        :taskCode = "subTaskInfo.taskCode"
                        :processConfigId = "item.processConfigId"
                        :elementIndex = "index"
                        :fixed="0"
                        preview-size="20"
                        @fileChange="fileChange"
                      />
                    </van-row>
                    <van-row class="rowLabel" v-if="sortNo == 6">
                      <van-col :span="6">
                        <van-button plain type="primary" size="mini" style="margin-left:70px;" @click="startGetSubTaskPoleGroupFilesFromAI(item)">获取极组照片</van-button>
                        <van-button plain type="primary" size="mini" style="margin-left:6px;" @click="querySubTaskPoleGroupFiles(item)">刷新照片</van-button>
                      </van-col>
                    </van-row>
                </van-collapse-item>
                </template>
              </van-collapse>
            </div>
  
            <!-- 查看节点2 -->
            <div v-if="this.subTaskInfo.status === '3' ">
              <van-row class="rowLabel">
                <van-col span="12"  class="colCss">
                    <div class="taskName">任务编号：</div>
                    <div class="taskInfo">{{subTaskInfo.taskCode}}</div>
                </van-col>
                <van-col span="12"  class="colCss">
                    <div class="taskName">任务名称：</div>
                    <div class="taskInfo">{{mainTaskInfo.taskName}}</div>
                </van-col>
              </van-row>
              <van-row class="rowLabel">
                <van-col span="12" class="colCss">
                  <div class="taskName">节点名称：</div>
                  <div class="taskInfo">{{taskNodeName}}</div>
                </van-col>
              </van-row>
              <van-row class="rowLabel">
                <van-col span="12" class="colCss">
                    <div class="taskName">电芯型号：</div>
                    <div class="taskInfo">{{subTaskInfo.electricCoreTypeName}}</div> 
                </van-col>
                <van-col span="12" class="colCss">
                  <div class="taskName">电芯编号：</div>
                  <div class="taskInfo">{{subTaskInfo.electricCoreCode}}</div>
                </van-col>
              </van-row>
              <!--固定元素-->
              <van-collapse v-model="fixedActiveIndexs">
                <template v-for="(item, index) in fixedConfigElementList">
                    <van-collapse-item :title="item.name" :name="index">
                      <van-row class="rowLabel" v-if="item.type === 1 || item.type === 5">
                        <van-col :span="item.unit ? 7 : 8" class="colCss">
                          <div class="taskName">{{ item.name }}：</div>
                          <div class="taskInfo">
                            {{ item.configValue }} &nbsp;&nbsp;
                            <template slot v-if="item.unit != null && item.unit != '' && item.configValue">
                              {{ item.unit }}
                            </template>
                          </div>
                        </van-col>
                      </van-row>
                      <!-- 缺陷判断选择框 -->
                      <van-row class="rowLabel" v-if="item.type === 3 || item.type === 5">
                        <van-col span="24" class="colCss">
                          <div class="taskName">是否缺陷：</div>
                          <div class="taskInfo">
                            {{ item.selectValue }}
                          </div>
                        </van-col>
                      </van-row>
                      <!--缺陷类型 -->
                      <van-row class="rowLabel" v-if="item.isThrowDesc === 1">
                        <van-col span="24" class="colCss">
                          <div class="taskName">缺陷类型：</div>
                          <div class="taskInfo">
                            {{ item.defectNames }}
                          </div>
                        </van-col>
                      </van-row>
                      <!--异常描述 -->
                      <van-row class="rowLabel" v-if="item.isThrowDesc === 1">
                        <van-col span="24" class="colCss">
                          <div class="taskName">异常描述：</div>
                          <div class="taskInfo">
                            {{ item.descr }}
                          </div>
                        </van-col>
                      </van-row>
                      <!-- 描述信息 -->
                      <van-row class="rowLabel" v-if="item.type == 4">
                        <van-col span="24" class="colCss">
                          <div class="taskName">问题描述:</div>
                          <div class="taskInfo">
                            {{item.configValue}}
                          </div>
                        </van-col>
                      </van-row>
                      <!--照片-->
                      <van-row class="rowLabel" v-if="item.hasImage === 1">
                        <van-col span="24" class="colCss">
                          <uploader 
                            :fileList="item.taskNodeFileList"
                            :title="'照片：'"
                            :taskCode = "subTaskInfo.taskCode"
                            :processConfigId = "item.processConfigId"
                            :elementIndex = "index"
                            :fixed="1"
                            :viewMode="true"
                            preview-size="20"
                          />
                        </van-col>
                      </van-row>
                    </van-collapse-item>
                </template>
              </van-collapse>
              
              <!-- 动态元素 -->
              <van-collapse v-model="dynActiveIndexs">
                <template v-for="(item, index) in dynConfigedElementList">
                    <van-collapse-item :title="item.name" :name="index">
                      <van-row class="rowLabel" v-if="item.type === 1 || item.type === 5">
                        <van-col :span="item.unit ? 7 : 8" class="colCss">
                          <div class="taskName">{{ item.name }}：</div>
                          <div class="taskInfo">
                            {{ item.configValue }} &nbsp;&nbsp;
                            <template slot v-if="item.unit != null && item.unit != '' && item.configValue">
                              {{ item.unit }}
                            </template>
                          </div>
                        </van-col>
                      </van-row>
                      <!-- 缺陷判断选择框 -->
                      <van-row class="rowLabel" v-if="item.type === 3 || item.type === 5">
                        <van-col span="24" class="colCss">
                          <div class="taskName">是否缺陷：</div>
                          <div class="taskInfo">
                            {{ item.selectValue }}
                          </div>
                        </van-col>
                      </van-row>
                      <!--缺陷类型 -->
                      <van-row class="rowLabel" v-if="item.isThrowDesc === 1">
                        <van-col span="24" class="colCss">
                          <div class="taskName">缺陷类型：</div>
                          <div class="taskInfo">
                            {{ item.defectNames }}
                          </div>
                        </van-col>
                      </van-row>
                      <!--异常描述 -->
                      <van-row class="rowLabel">
                        <van-col span="24" class="colCss">
                          <div class="taskName">异常描述：</div>
                          <div class="taskInfo">
                            {{ item.descr }}
                          </div>
                        </van-col>
                      </van-row>
                      <!-- 描述信息 -->
                      <van-row class="rowLabel">
                        <van-col span="24" class="colCss">
                          <div class="taskName">问题描述:</div>
                          <div class="taskInfo">
                            {{item.configValue}}
                          </div>
                        </van-col>
                      </van-row>
                      <!--照片-->
                      <van-row class="rowLabel" v-if="item.hasImage === 1">
                        <van-col span="24" class="colCss">
                          <uploader 
                            :fileList="item.taskNodeFileList"
                            :title="'照片：'"
                            :taskCode = "subTaskInfo.taskCode"
                            :processConfigId = "item.processConfigId"
                            :elementIndex = "index"
                            :fixed="0"
                            :viewMode="true"
                            preview-size="20"
                          />
                        </van-col>
                      </van-row>
                    </van-collapse-item>
                </template>
              </van-collapse>  
            </div>
          </van-form>
    </div>
  </template>
  
  <script>
    import { Toast } from 'vant';
    import { Dialog } from 'vant';
    import uploader from '../uploader.vue';
    import VanFieldCheckbox from '../../../components/VanFieldCheckbox.vue';
    import { getDynamicConfigElementList } from "@/apis/index";
    import { deleteDynamicConfigElement } from '@/apis/index';
    import { deleteTaskNodeFile } from '@/apis/index';
    import { getSubTaskPoleGroupFiles } from '@/apis/index';
    import { getSubTaskPoleGroupFilesFromAI } from '@/apis/index';
  
    export default {
        components: { uploader, VanFieldCheckbox },
        props: {
            formDataProp: {
                type: Object,
                default: {}
            },
            mainTaskInfoProp: {
                type: Object,
                default: {}
            },
            subTaskInfoProp: {
                type: Object,
                default: {}
            },
            taskNodeNameProp: {
                type: String,
                default: ''
            },
            sortNoProp: {
                type: Number,
                default: null
            }
        },
        data() {
            return {
              formData: {},
              subTaskInfo: {},
              mainTaskInfo: {},
              taskNodeName: '',
              defectList: [],
              showPicker: false,
              showAddElementPopup: false,
              sortNo: null,
              okColumns: [
                { text: 'OK', value: 'OK' },
                { text: 'NOK', value: 'NOK' }
              ],
              fixedConfigElementList: [], // 固定元素
              dynConfigedElementList: [],    // 动态配置的元素
              dynConfigurableElementList: [],  // 可动态配置的元素
              fixedActiveIndexs: [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20],
              dynActiveIndexs: [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20],
              dynElementNameList: [],
              defectTypeIds: []
            }
        },
        created() {
        },
        mounted() {
          this.initDynamicConfigurableElementList();
        },
        watch: {
            formDataProp: {
                handler(newVal, oldVal) {
                    this.formData = newVal;
                    if (newVal.nodeInstConfigValueList) {
                      this.fixedConfigElementList = [];
                      this.dynConfigedElementList = [];

                      // 为动态元素绑定对应的数据源
                      newVal.nodeInstConfigValueList.forEach((item, index) => {
                        if (item.fixed == 1) {
                          let index = this.fixedConfigElementList.length;
                          this.fixedConfigElementList.push(item);
  
                          item.okColumns = [
                            { text: 'OK', value: 'OK', elementIndex:  index },
                            { text: 'NOK', value: 'NOK', elementIndex:  index }
                          ];
                          item.showPicker = false;
                          item.showDefectTypePicker = false;
                          item.noDefectType = false;
                          if (item.selectValue === 'OK')
                            item.noDefectType = true;
                          
                          let defectTypeList = [{
                            text: '无',
                            value: null,
                            elementIndex:  index
                          }];
                          item.currentNodeDefectTypeList = newVal.currentNodeDefectTypeList;
                          item.defectTypeIdList = []
                          if (item.defectTypeList) {
                            item.defectTypeIdList = item.defectTypeList.map(item => item.defectTypeId)
                            item.defectNames = item.defectTypeList.map(item => item.defectName).join('、')
                          }
                        }
                        else if (item.fixed == 0) {
                          let index = this.dynConfigedElementList.length;
                          this.dynConfigedElementList.push(item);
  
                          item.okColumns = [
                            { text: 'OK', value: 'OK', elementIndex:  index },
                            { text: 'NOK', value: 'NOK', elementIndex:  index }
                          ];
                          item.showPicker = false;
                          item.showDefectTypePicker = false;
                          item.noDefectType = false;
                          if (item.selectValue === 'OK')
                            item.noDefectType = true;

                          item.currentNodeDefectTypeList = newVal.currentNodeDefectTypeList;
                          item.defectTypeIdList = []
                          if (item.defectTypeList) {
                            item.defectTypeIdList = item.defectTypeList.map(item => {
                              return item.defectTypeId
                            })
                          }
                        }
                      })
                    }
                },
                deep: false,
                immediate: true
            },
            mainTaskInfoProp: {
                handler(newVal, oldVal) {
                    this.mainTaskInfo = newVal;
                },
                deep: true,
                immediate: true
            },
            subTaskInfoProp: {
                handler(newVal, oldVal) {
                    this.subTaskInfo = newVal;
                },
                deep: true,
                immediate: true
            },
            sortNoProp: {
                handler(newVal, oldVal) {
                    this.sortNo = newVal;
                },
                deep: true,
                immediate: true
            },
            taskNodeNameProp: {
                handler(newVal, oldVal) {
                    this.taskNodeName = newVal;
                },
                deep: true,
                immediate: true
            }
        },
        methods: {
          // 获取表单数据
          getFormData(commonParam) {
            let param = JSON.parse(JSON.stringify(commonParam));
            param.defectTypeIdList = this.formData.defectTypeIdList;
            param.electricCoreWeight = this.formData.electricCoreWeight;
            param.remark = this.formData.remark;
            param.export = {}
            param.export.weight = this.formData.electricCoreWeight;
            param.nodeInstConfigValueList = this.fixedConfigElementList;  // 复制固定元素
            if (this.dynConfigedElementList.length > 0)
              param.nodeInstConfigValueList.push.apply(param.nodeInstConfigValueList, this.dynConfigedElementList);    // 复制动态元素
            return param
          },
          // 初始化可动态配置的元素列表
          initDynamicConfigurableElementList() {
            getDynamicConfigElementList().then(res => {
              if (res.code === 1) {
                this.dynConfigurableElementList = res.data;
                res.data.forEach(item => {
                  this.dynElementNameList.push({ value: item.id, text: item.name });
                })
              }
            })
          },
          // 动态创建元素
          confirmDynElement(selectedValue, selectedIndex) {
            this.showAddElementPopup = false;
            let configurableElement = this.dynConfigurableElementList.find(function(item, index, arr) {
              return selectedValue.value == item.id;
            });
            if (configurableElement != null) {
              let dayConfigedElementLength = this.dynConfigedElementList.length;
              this.dynConfigedElementList.push({
                configValue: null,
                descr: null,
                defectTypeIdList: [],
                fixed: configurableElement.fixed,
                hasImage: configurableElement.hasImage,
                isThrowDesc: configurableElement.isThrowDesc,
                name: configurableElement.name,
                type: configurableElement.type,
                unit: configurableElement.unit,
                okColumns: [
                          { text: 'OK', value: 'OK', elementIndex:  dayConfigedElementLength },
                          { text: 'NOK', value: 'NOK', elementIndex:  dayConfigedElementLength }
                        ],
                currentNodeDefectTypeList: this.formData.currentNodeDefectTypeList,
                processConfigId: selectedValue.value
              })
            }
          },
          // 删除动态元素
          deleteDynElement(index) {
            Dialog.confirm({
              title: '提示',
              message: '是否删除'
            }).then(() => {
              if (this.dynConfigedElementList[index].id) {
                deleteDynamicConfigElement(this.dynConfigedElementList[index].id);
              }
              this.dynConfigedElementList.splice(index, 1);
              if (this.dynConfigedElementList && this.dynConfigedElementList.length > 0) {
                // 调整下拉选择框对应的元素下标
                for (var i = 0; i < this.dynConfigedElementList.length; i++) {
                  this.dynConfigedElementList[i].okColumns[0].elementIndex = i;
                  this.dynConfigedElementList[i].okColumns[1].elementIndex = i;
    
                  this.dynConfigedElementList[i].defectTypeList.forEach(item => {
                    item.elementIndex = i;
                  })
                }
              }
            }).catch(() => {

            })
          },
          // 确认OK下拉选择
          onConfirmOK(selectedValue) {
            if (selectedValue.elementIndex > -1) {
              this.fixedConfigElementList[selectedValue.elementIndex].selectValue = selectedValue.value;
              if (selectedValue.value === 'OK') {
                this.fixedConfigElementList[selectedValue.elementIndex].noDefectType = true;
                this.fixedConfigElementList[selectedValue.elementIndex].defectTypeList = [];
                this.fixedConfigElementList[selectedValue.elementIndex].descr = '';
              } else {
                this.fixedConfigElementList[selectedValue.elementIndex].noDefectType = false;
              }
              this.hideElementPicker(selectedValue.elementIndex, 1);
            }
          },
          // 确认动态OK下拉选择
          onConfirmDynOK(selectedValue, selectedOptions, selectedIndexes) {
            if (selectedValue.elementIndex > -1) {
              this.dynConfigedElementList[selectedValue.elementIndex].selectValue = selectedValue.value;
              if (selectedValue.value === 'OK') {
                this.dynConfigedElementList[selectedValue.elementIndex].noDefectType = true;
                this.dynConfigedElementList[selectedValue.elementIndex].defectTypeList = [];
                this.dynConfigedElementList[selectedValue.elementIndex].descr = '';
              } else {
                this.dynConfigedElementList[selectedValue.elementIndex].noDefectType = false;
              }
              this.hideElementPicker(selectedValue.elementIndex, 2);
            }
          },
          // 确认缺陷类型
          onConfirmDefectType(selectedValue, selectedOptions, selectedIndexes) {
            if (selectedValue.elementIndex > -1) {
              this.fixedConfigElementList[selectedValue.elementIndex].defectTypeId = selectedValue.value;
              this.fixedConfigElementList[selectedValue.elementIndex].defectTypeName = selectedValue.text;
              this.hideDefectPicker(selectedValue.elementIndex, 1);
            }
          },
          // 确认动态缺陷类型
          onConfirmDynDefectType(selectedValue, selectedOptions, selectedIndexes) {
            if (selectedValue.elementIndex > -1) {
              this.dynConfigedElementList[selectedValue.elementIndex].defectTypeId = selectedValue.value;
              this.dynConfigedElementList[selectedValue.elementIndex].defectTypeName = selectedValue.text;
              this.hideDefectPicker(selectedValue.elementIndex, 2);
            }
          },
          // 显示元素
          showElementPicker(index, elementType) {
            console.log(this.fixedConfigElementList[index])
            if (elementType === 1)
              this.fixedConfigElementList[index].showPicker = true;
            else if (elementType === 2)
              this.dynConfigedElementList[index].showPicker = true;
          },
          // 隐藏元素
          hideElementPicker(index, elementType) {
            if (elementType === 1)
              this.fixedConfigElementList[index].showPicker = false;
            else if (elementType === 2)
              this.dynConfigedElementList[index].showPicker = false;
          },
          // 显示缺陷类型选择
          showDefectPicker(index, elementType) {
            if (elementType == 1 && !this.fixedConfigElementList[index].noDefectType)
              this.fixedConfigElementList[index].showDefectTypePicker = true;
            else if (elementType == 2 && !this.dynConfigedElementList[index].noDefectType)
              this.dynConfigedElementList[index].showDefectTypePicker = true;
          },
          // 隐藏缺陷类型选择
          hideDefectPicker(index, elementType) {
            if (elementType == 1)
              this.fixedConfigElementList[index].showDefectTypePicker = false;
            else if (elementType == 2)
              this.dynConfigedElementList[index].showDefectTypePicker = false;
          },
          fileChange(action, fixed, elementIndex, data) {    
                if (action === 'add') {
                    let elementList = fixed === 1 ? this.fixedConfigElementList : this.dynConfigedElementList;
                    if (!elementList[elementIndex].fileList) {
                        elementList[elementIndex].fileList = [];
                    }
                    elementList[elementIndex].fileList.push(data);
                } else if (action === 'delete') {
                    let param = {
                      id: data.id,
                      filePath: data.filePath
                    };
                    deleteTaskNodeFile(param).then(res => {
                      if(res.code === 1) {
                        let elementList = fixed === 1 ? this.fixedConfigElementList : this.dynConfigedElementList;
                        let index = elementList[elementIndex].fileList.findIndex((item) => {
                            return item.fileName == data.fileName;
                        })
                        if (index > -1) {
                            elementList[elementIndex].fileList.splice(index, 1);
                        }
                        Toast('附件删除成功');
                      }else{
                        Toast(res.msg);
                      }
                    })
                }
          },
          startGetSubTaskPoleGroupFilesFromAI(item) {
            if (!item.configValue) {
              Dialog.alert({
                title: '提示',
                message: item.name + '不能为空！'
              });
              return;
            }

            // 校验极组编号是否重复
            let duplicate = this.checkPoleGroupNumberDuplicate(item);
            if (duplicate) {
              Dialog.alert({
                title: '提示',
                message: '极组条码重复'
              });
              return;
            }

            let params = {
              subTaskId: this.subTaskInfo.id,
              taskNodeId: this.formData.taskNodeId,
              taskNodeInstId: this.formData.taskNodeInstId,
              electricCoreCode: this.subTaskInfo.electricCoreCode,
              poleGroupNumber: item.configValue
            }
            getSubTaskPoleGroupFilesFromAI(params)
              .then(res => {
                if (res.code === 1) {
                  Dialog.alert({
                    title: '提示',
                    message: '开始获取接口极组照片'
                  });
                } else if (res.code === 14025) {
                  Dialog.confirm({
                    title: '提示',
                    message: '接口极组照片获取完成，确认重新获取？'
                  }).then(() => {
                    params.mandatoryReGet = 1
                    getSubTaskPoleGroupFilesFromAI(params)
                      .then(res => {
                        if (res.code === 1)
                          Dialog.alert({
                            title: '提示',
                            message: '开始获取接口极组照片，请稍后点击刷新图片查看。'
                          });
                      });
                  })
                }
              })
          },
          querySubTaskPoleGroupFiles(item) {
            let params = {
              subTaskId: this.subTaskInfo.id,
              taskNodeId: this.formData.taskNodeId,
              taskNodeInstId: this.formData.taskNodeInstId,
              subTaskNodeInstId: this.formData.subTaskNodeInstId,
              electricCoreCode: this.subTaskInfo.electricCoreCode,
              poleGroupNumber: item.configValue,
              processRelationId: item.id
            }
            getSubTaskPoleGroupFiles(params)
              .then(res => {
                if (res.code === 1) {
                  item.currentNodeDefectTypeList = res.data.defectTypeList;
                  if (!item.defectTypeIdList)
                    item.defectTypeIdList = [];
                  if (!item.defectTypeList)
                    item.defectTypeList = [];
                  if (res.data.defectTypeListNew) {
                    let defectTypeIdListNew = res.data.defectTypeListNew.map(item => {
                      return item.defectTypeId;
                    })
                    item.defectTypeIdList.push.apply(item.defectTypeIdList, defectTypeIdListNew);
                    item.defectTypeIdList = Array.from(new Set(item.defectTypeIdList));
                    item.defectTypeList = item.currentNodeDefectTypeList.filter(e => 
                      item.defectTypeIdList.indexOf(e.defectTypeId) > -1
                    )
                  }

                  item.taskNodeFileList = [];
                  item.taskNodeFileList.push.apply(item.taskNodeFileList, res.data.taskNodeFileList);

                  let newFileList = res.data.taskNodeFileList.filter(e => e.id === null);
                  item.fileList = [];
                  item.fileList.push.apply(item.fileList, newFileList);

                  if (res.data.desc != '') {
                    item.descr = res.data.desc;
                  }
                }
              })
          },
          checkPoleGroupNumberDuplicate(item) {
            let duplicate = this.fixedConfigElementList.findIndex(e => e.configValue === item.configValue && e.name.match(/极组条码/g) && item.name.match(/极组条码/g) && !Object.is(item, e));
            if (duplicate > -1) {
              return true;
            }
            duplicate = this.dynConfigedElementList.findIndex(e => e.configValue === item.configValue && e.name.match(/极组条码/g) && item.name.match(/极组条码/g) && !Object.is(item, e));
            if (duplicate > -1) {
              return true;
            }
            return false;
          },
          selectDefectType(defectTypeIdList, defectTypeList, item) {
            item.defectTypeList = defectTypeList
          }
        }
    }
  </script>
  
  <style lang="scss" scoped>
  .rowLabel {
  color: #646566;
  .colCss {
    padding: 10px 16px;
  }
  }
  
  .rowLabel{
  .taskName{
    display: inline-block;
    width: 6.2em;
  }
  .taskInfo{
    display: inline-block;
    margin-left:12px;
  }
  }
  
  .defectSelect{
  .van-cell__value,.van-field__value{
    border: none!important;
    padding: 0px!important;
  }
  }
  
  .formUnit{
  line-height:56px;
  }
</style>